// AnsiEditorView.h : interface of the CAnsiEditorView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_ANSIEDITORVIEW_H__C07975CE_FFE8_11D7_B08F_0002553118A0__INCLUDED_)
#define AFX_ANSIEDITORVIEW_H__C07975CE_FFE8_11D7_B08F_0002553118A0__INCLUDED_

#include "CellInfo.h"	// Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

typedef enum enumEditTool
{
	TOOL_ARROW		 = ID_TOOL_ARROW,
	TOOL_STAMP		 = ID_TOOL_STAMP,
	TOOL_RUBBER		 = ID_TOOL_RUBBER,
	TOOL_FLOODFILL	 = ID_TOOL_FLOODFILL,
	TOOL_COLORPICKER = ID_TOOL_COLORPICKER,
	TOOL_FORMATBRUSH = ID_TOOL_FORMATBRUSH
} EDIT_TOOL;

typedef enum CELLINFOMASK
{
	MASK_CHAR		= 0x0001,
	MASK_BLINK		= 0x0002,
	MASK_HIGHLIGHT	= 0x0004,
	MASK_REVERSE	= 0x0008,
	MASK_SELECTED	= 0x0010,
	MASK_UNDERLINE	= 0x0020,
	MASK_BACKCOLOR	= 0x0040,
	MASK_FONTINDEX	= 0x0080,
	MASK_FORECOLOR	= 0x0100,

} CELLINFOMASK;

class CAppContext;

typedef enum 
{
	DRAG_UNKNOWN,
	DRAG_MOVE,
	DRAG_COPY,
} DragAction;

typedef CArray<CPoint, const CPoint&> CPointArray;

class CAnsiEditorView : public CScrollView
{
private:
	//typedef struct 

protected: // create from serialization only
	CAnsiEditorView();
	DECLARE_DYNCREATE(CAnsiEditorView)

// Attributes
public:
	void InsertText(CSize size, LPCTSTR szText);
	CAppContext *gpUIContext;

	CAnsiEditorDoc* GetDocument();
	CPoint &GetCaretPos()
	{
		return m_ptCaret;
	}
	void SetCaretPos(CPoint ptCaret)
	{
		ASSERT(ptCaret.x >= 0 && ptCaret.y >= 0 && ptCaret.x <= MAX_COL - 1 && ptCaret.y <= MAX_ROW - 1);
		m_ptCaret = ptCaret;
		PositionCaret();
	}

// Operations
public:
//	void OnUpdateTools(CCmdUI* pCmdUI);
	void UpdateCharBoxPos();
	void SetCurTool(EDIT_TOOL tool);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAnsiEditorView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual void OnInitialUpdate();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
	protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
	//}}AFX_VIRTUAL

// Implementation
public:
	CCellInfo GetCaretCellInfo();
	void UpdateRegion(CRect rcRegion);
	BOOL DoReplace(int nRange, CString sText1, CString sText2, int nFore1, int nFore2, 
		int nBack1, int nBack2, BOOL simpleColorReplace, BOOL highlightColorSense);

	BOOL IsSelected()
	{
		return m_bSelected;
	}
	CString GetSelectedText();
	CString GetCaretChar();
	CRect GetSelecetdRange();
	void AddHistoryStep();
	BOOL m_bForeTransparent;
	BOOL m_bBackTransparent;
	void UpdateCanvasMode(BOOL bUpdateFont = FALSE);
	void UpdateDocSize();
	EDIT_TOOL m_curTool;
	void OnBackColor(int nBackColor, BOOL bAffectCurChar);
	void OnForeColor(int nForeColor, BOOL bAffectCurChar);
	CCellInfo m_curCellInfo;
	void SetGridColor(COLORREF clrDot1, COLORREF clrDot2);
	virtual ~CAnsiEditorView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	void _createCaret(COLORREF bgColor = 0);
	void DoSelecting(CPoint ptCur);
	//
	void GetTableCharPoints(CRect rect, CPointArray& pa);
	void GetTableCharPoints(CPoint point, CPointArray& pa);
	BOOL m_bSingleCharDragging;
	BOOL m_bTableMode;
	WINDOWPLACEMENT m_wpFrame;
	CRect GetSeamlessFrameRect();
	BOOL m_bIgnoreThisChar;
	void KillEofLine();
	void PasteSpecial(int nPasteType);
	BOOL m_bRDowned;
	void EnsureCaretVisible();
	BOOL m_bInsMode;
	char m_LastChar[3];
	void FloodFill(int x, int y, BOOL bForeGround);
	void OnFloodFill(CPoint &pt);
	CString m_sStampChar;
	void OnStamp(CPoint &pt);
	void OnRubber(CPoint &pt);
	void OnBrush(CPoint &pt);
	void CancelSelected();
	void SetCellsInfo(CRect &rect, CCellInfo &cellinfo, UINT mask);
	void DeleteChar();
	void PasteCachedData(int x, int y, BOOL bEmptyCache = TRUE);
	CSize m_sizeCached;
	void CacheSelectedData();
	CArray< CCellInfo, CCellInfo& > m_arrCachedCells;
	CArray< char, char > m_arrCachedChars;
	void DeleteSelected();
	COLORREF m_clrWorkSpaceBack;
	BOOL SetBackPicture(LPCTSTR lpszPicture);
	LPPICTURE m_pBackPicture;
	void UpdateCanvasSize(int cx = 0, int cy = 0, BOOL bUpdateFont = FALSE);
	void UpdateScrollBar();
	CBrush m_brushGrid;
	CStatic m_wndDrag;
	BOOL m_bDraging;
	void BeginDrag(DragAction dragAction = DRAG_UNKNOWN);
	void EndDrag();
	CPoint m_ptDownedPixel;
	CPoint m_ptMovingOffset;
//	BOOL m_bMoving;
	CRect m_rcOriSelected;
	void DrawSelectRect(CDC &dc);
	CPen m_penWhiteDot;
	CPen m_penBlackDot;
	BOOL m_bSelecting;
	void SetRangeSelected(const CRect &rcRange, BOOL bSelected);
	CPoint m_ptMoving;
	BOOL m_bDowned;
	BOOL TranslatePoint(CPoint ptPixel, CPoint &ptGrid, BOOL TranslateEvenFail = TRUE);
	CPoint m_ptDowned;
	BOOL m_bSelected;
	CRect m_rcSelected;
	void PositionCaret();
	CPoint m_ptCaret;
	CPen m_penGrid;
	BOOL m_bBlinking;
	COLORREF m_clrBack;
	int m_nCellWidth;
	int m_nCellHeight;
	CFont m_font;
	//{{AFX_MSG(CAnsiEditorView)
	afx_msg void OnCancelEditSrvr();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnToolHighLight();
	afx_msg void OnToolHorzTrans();
	afx_msg void OnToolVertTrans();
	afx_msg void OnToolUnHighLight();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnViewPicture();
	afx_msg void OnFormatBlink();
	afx_msg void OnUpdateFormatBlink(CCmdUI* pCmdUI);
	afx_msg void OnFormatUnderline();
	afx_msg void OnUpdateFormatUnderline(CCmdUI* pCmdUI);
	afx_msg void OnUpdateFormatReverse(CCmdUI* pCmdUI);
	afx_msg void OnFormatReverse();
	afx_msg void OnFormatFont();
	afx_msg void OnEditCut();
	afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
	afx_msg void OnEditCopy();
	afx_msg void OnEditPaste();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnEditUndo();
	afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
	afx_msg void OnUpdateEditRedo(CCmdUI* pCmdUI);
	afx_msg void OnEditRedo();
	afx_msg void OnEditDelete();
	afx_msg void OnUpdateEditDelete(CCmdUI* pCmdUI);
	afx_msg void OnViewCharbox();
	afx_msg void OnUpdateViewCharbox(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolHorztrans(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolVerttrans(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolHighlight(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolUnhighlight(CCmdUI* pCmdUI);
	afx_msg void OnExport();
	afx_msg void OnRenderFormat(UINT nFormat);
	afx_msg void OnRenderAllFormats();
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnEditLastchar();
	afx_msg void OnCopyText();
	afx_msg void OnPasteIgnoreAll();
	afx_msg void OnPasteIgnoreBack();
	afx_msg void OnPasteIgnoreFore();
	afx_msg void OnEditClearAll();
	afx_msg void OnViewSeamless();
	afx_msg void OnUpdateViewSeamless(CCmdUI* pCmdUI);
	afx_msg void OnEditSelectAll();
	afx_msg void OnUpdateTableSetTableLine(CCmdUI* pCmdUI);
	afx_msg void OnTableSetTableLine();
	afx_msg void OnUpdateTableTablemode(CCmdUI* pCmdUI);
	afx_msg void OnTableTablemode();
	afx_msg void OnTableStyle();
	afx_msg void OnTableInserttable();
	afx_msg void OnTablePastetable();
	//}}AFX_MSG
	afx_msg void OnCharset();
	afx_msg void OnFormatFontMenu(UINT nID);
	afx_msg void OnUpdateFormatFontMenu(CCmdUI *pCmdUI);
	afx_msg LRESULT OnImeStartComposition(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnImeEndComposition(WPARAM wParam, LPARAM lParam);
	afx_msg void OnUpdateTools(CCmdUI* pCmdUI);
	afx_msg void OnTools(UINT nID);
	afx_msg void OnUpdateCharsetMenu(CCmdUI *pCmdUI);
	afx_msg void OnCharsetMenu(UINT nID);
	afx_msg void OnCharSetConfig();
	afx_msg void OnUpdateIndicatorSize(CCmdUI *pCmdUI);
	afx_msg void OnUpdateIndicatorXY(CCmdUI *pCmdUI);
	afx_msg void OnUpdateIndicatorIns(CCmdUI *pCmdUI);
	afx_msg void OnViewText();
	afx_msg void OnViewBack();
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in AnsiEditorView.cpp
inline CAnsiEditorDoc* CAnsiEditorView::GetDocument()
   { return (CAnsiEditorDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ANSIEDITORVIEW_H__C07975CE_FFE8_11D7_B08F_0002553118A0__INCLUDED_)
